//
//  BRWalletBaseTCell.m
//  BrezzeSaaS
//
//  Created by 甘卫国 on 2023/12/1.
//  Copyright © 2023 Brezze GWG. All rights reserved.
//

#import "BRWalletBaseTCell.h"

@implementation BRWalletBaseTCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (void)btnAction:(QMUIButton *)btn {
    if (self.btnClickBlock) {
        self.btnClickBlock(btn.selected);
    }
}

- (void)setAmountStr:(NSString *)amountStr {
    _amountStr = amountStr;
    
    self.amountL.text = amountStr;
}

#pragma mark - UI --
- (void)setUI {
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    UIView *bg = [[UIView alloc] init];
//    bg.layer.cornerRadius = 13;
//    bg.layer.masksToBounds = YES;
    [self.contentView addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(20);
        make.right.offset(-20);
        make.bottom.offset(0);
    }];
    _bgView = bg;
    
    UIImageView *bgImg = [[UIImageView alloc] init];
    [bg addSubview:bgImg];
    [bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    
    NSString *imgName = @"wallet_depositBG";
    UIImage *bubble = UIImageMake(imgName);
    
    bgImg.image = [bubble resizableImageWithCapInsets:UIEdgeInsetsMake(48, 48, 48, 48) resizingMode:UIImageResizingModeStretch];
    bgImg.contentMode = UIViewContentModeScaleToFill;
    
    UIView *titleBG = [[UIView alloc] init];
    titleBG.backgroundColor = UIColor.clearColor;
    
    self.leftImg = [[UIImageView alloc] initWithImage:UIImageMake(@"card_default")];
    [titleBG addSubview:self.leftImg];
    [self.leftImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.width.mas_equalTo(16);
        make.height.mas_equalTo(16);
        make.bottom.offset(0);
        make.top.offset(0);
    }];
    
    self.typeL = [BRToolsView br_label:@"--" textColor:UIColor.whiteColor font:[UIFont fontS:14]];
    
    [titleBG addSubview:self.typeL];
    [self.typeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftImg.mas_right).offset(6);
        make.centerY.offset(0);
        make.right.offset(0);
    }];
    
    UIStackView *stackView = [[UIStackView alloc] init];
    stackView.axis = UILayoutConstraintAxisVertical;
    stackView.spacing = 8;
    [bg addSubview:stackView];
    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-80);
        make.left.offset(28);
        make.top.offset(16);
        make.bottom.offset(-16);
    }];
    
  
    
    self.tipsL = [BRToolsView br_label:@"--" textColor:UIColor.whiteColor font:[UIFont br_fontR:9]];
    self.tipsL.numberOfLines = 0;
    self.amountL = [BRToolsView br_label:@"--" textColor:UIColor.whiteColor font:[UIFont br_fontB:23]];
    
    [stackView addArrangedSubview:titleBG];
    [stackView addArrangedSubview:self.tipsL];
    [stackView addArrangedSubview:self.amountL];
    
    QMUIButton *btn = [[QMUIButton alloc] init];
    [btn setTitle:@"--" forState:UIControlStateNormal];
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont br_fontS:12];
    btn.layer.cornerRadius = 14;
    btn.layer.masksToBounds = YES;
    btn.layer.borderWidth = 0.5;
    btn.layer.borderColor = UIColor.whiteColor.CGColor;
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 12, 0, 12)];
    [bg addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(28);
        make.centerY.equalTo(self.amountL.mas_centerY).offset(0);
        make.right.offset(-16);
        make.width.mas_greaterThanOrEqualTo(74);
    }];
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    _btn = btn;
    
    
    UIImageView *rImg = [[UIImageView alloc] initWithImage:UIImageMake(@"wallet_line")];
    [bg insertSubview:rImg atIndex:1];
    [rImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(90);
        make.top.offset(0);
    }];
}

@end

@implementation BRWalletDepositTCell

- (void)setIsTopUp:(BOOL)isTopUp {
    _isTopUp = isTopUp;
    self.btn.selected = isTopUp;
    NSString *str = isTopUp == YES ? Localized(@"wallet_refund") : Localized(@"wallet_addDeposit");
    [self.btn setTitle:str forState:UIControlStateNormal];
    [self.btn setTitle:str forState:UIControlStateSelected];
   
}

- (void)setUI {
    [super setUI];
    
    self.leftImg.image = UIImageMake(@"wallet_deposit");
    [self.btn setTitle:Localized(@"wallet_addDeposit") forState:UIControlStateNormal];
    
    self.typeL.text = Localized(@"wallet_deposit");
    self.tipsL.text = Localized(@"wallet_depositTips");
}

@end

@implementation BRWalletPrepaymentTCell


- (void)toRefund {
    if (self.btnClickBlock) {
        self.btnClickBlock(YES);
    }
}


- (void)setIsPrepayment:(BOOL)isPrepayment {
    _isPrepayment = isPrepayment;
//    self.btn.selected = isPrepayment;
//    NSString *str = isPrepayment == YES ? Localized(@"Order_refund") : Localized(@"Payment_pay");
//    [self.btn setTitle:str forState:UIControlStateNormal];
//    [self.btn setTitle:str forState:UIControlStateSelected];
    
    self.reFundBtn.hidden = !isPrepayment;
   
}

- (void)setUI {
    [super setUI];
    
    [self.leftImg mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.offset(24);
        make.width.mas_equalTo(44);
        make.height.mas_equalTo(36);
    }];
    self.leftImg.image = UIImageMake(@"wallet_prepayment");
    [self.btn setTitle:Localized(@"Payment_pay") forState:UIControlStateNormal];
    
    self.typeL.text = Localized(@"wallet_prepayment");
    self.tipsL.text = Localized(@"wallet_preTips");
    self.typeL.numberOfLines = 0;
    [self.reFundBtn setImage:UIImageMake(@"wallet_refunded_white") forState:UIControlStateNormal];
    [self.bgView addSubview:self.reFundBtn];
    [self.reFundBtn addTarget:self action:@selector(toRefund) forControlEvents:UIControlEventTouchUpInside];
    [self.reFundBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(44);
        make.right.offset(0);
        make.top.offset(3);
    }];
    
}


- (QMUIButton *)reFundBtn {
    
    if (_reFundBtn == nil) {
        _reFundBtn = [[QMUIButton alloc] init];
    }
    
    return _reFundBtn;
}

@end


@implementation BRApplePreCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    
    self.contentView.backgroundColor = UIColor.qd_backgroundColor;
    
//    self.btn.isEnable = YES;
//    [self.contentView addSubview:self.btn];
//    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.offset(0);
//        make.bottom.offset(-20);
//        make.right.offset(-28);
//        make.left.offset(28);
//        make.height.mas_equalTo(54);
//    }];
}

//- (BRBroderBtn *)btn {
//    
//    if (_btn == nil) {
//        _btn = [[BRBroderBtn alloc] init];
//    }
//    return _btn;
//}

@end

@implementation BRApplePreEnableCell

#pragma mark - UI --
- (void)setUI {
    self.contentView.backgroundColor = UIColor.qd_backgroundColor;
    
    UIView *bg = [[UIView alloc] init];
    bg.backgroundColor = UIColorMakeWithHex(@"#F2F5FA");
    bg.layer.cornerRadius = 20;
    bg.layer.masksToBounds = YES;
    bg.layer.borderWidth = 0.5;
    bg.layer.borderColor = UIColorMakeWithHex(@"#D2D8E2").CGColor;
    [self.contentView addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(28);
        make.right.offset(-28);
        make.bottom.offset(-20);
        make.height.mas_equalTo(142);
    }];
    
//    [bg addSubview:self.btn];
//    self.btn.isEnable = NO;
//    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.offset(20);
//        make.right.offset(-28);
//        make.left.offset(28);
//        make.height.mas_equalTo(54);
//    }];
    
    
//    QMUIButton *btn = [[QMUIButton alloc] init];
//    [btn setTitle:Localized(@"wallet_revokeAuthorization") forState:UIControlStateNormal];
//    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
//    [btn setBackgroundColor:UIColorMakeWithHex(@"#646B80")];
//    btn.titleLabel.font = [UIFont br_fontS:14];
//    btn.layer.cornerRadius = 18;
//    btn.layer.masksToBounds = YES;
//    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 12, 0, 12)];
//    [bg addSubview:btn];
//    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(36);
//        make.top.equalTo(self.btn.mas_bottom).offset(16);
//        make.centerX.offset(0);
//        make.bottom.offset(-16);
//    }];
//    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}

@end


@implementation BRWalletCardBaseTCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (void)toSet {
    if (self.toSetBlock) {
        self.toSetBlock();
    }
}

#pragma mark - UI --
- (void)setUI {
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    UIView *bg = [[UIView alloc] init];
    [self.contentView addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(20);
        make.bottom.offset(0);
        make.right.offset(-20);
    }];
    _bg = bg;

    UIImageView *bgImg = [[UIImageView alloc] init];
    [bg addSubview:bgImg];
    [bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    
    UIImage *bubble = UIImageMake(@"wallet_bankcardBG");

    bgImg.image = [bubble resizableImageWithCapInsets:UIEdgeInsetsMake(48, 48, 48, 48) resizingMode:UIImageResizingModeStretch];
    bgImg.contentMode = UIViewContentModeScaleToFill;
    _bgImg = bgImg;
    
    UIView *titleBG = [[UIView alloc] init];
    titleBG.backgroundColor = UIColor.clearColor;
    
    UIImageView *rImg = [[UIImageView alloc] initWithImage:UIImageMake(@"card_ic")];
    [bg addSubview:rImg];
    [rImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-28);
        make.width.mas_equalTo(48);
        make.height.mas_equalTo(36);
        make.top.offset(20);
    }];
    
    // ---------------------
    UIStackView *stackView = [[UIStackView alloc] init];
    stackView.axis = UILayoutConstraintAxisVertical;
    stackView.spacing = 12;
    [bg addSubview:stackView];
    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-80);
        make.left.offset(28);
        make.top.offset(20);
    }];
    _stackView = stackView;
    
    UIView *top = [[UIView alloc] init];
    [stackView addArrangedSubview:top];
    [top mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
    }];
    
    self.cardImg = [[UIImageView alloc] init];
    [top addSubview:self.cardImg];
    [self.cardImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.width.mas_equalTo(28);
//        make.height.mas_equalTo(16);
        make.top.bottom.offset(0);
    }];
    
    self.nameL = [BRToolsView br_label:@"--" textColor:UIColor.whiteColor font:[UIFont br_fontS:14]];
    [top addSubview:self.nameL];
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardImg.mas_right).offset(8);
        make.centerY.offset(0);
    }];
    
   
    
    // --------------
    QMUIButton *set = [[QMUIButton alloc] init];
    [set setTitle:@"--" forState:UIControlStateNormal];
    [set setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    set.titleLabel.font = [UIFont br_fontS:12];
    set.layer.cornerRadius = 14;
    set.layer.masksToBounds = YES;
    set.layer.borderWidth = 0.5;
    set.layer.borderColor = UIColor.whiteColor.CGColor;
    [set setTitleEdgeInsets:UIEdgeInsetsMake(0, 12, 0, 12)];
    [bg addSubview:set];
    [set mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(28);
        make.bottom.offset(-16);
        make.right.offset(-16);
        make.width.mas_greaterThanOrEqualTo(74);
    }];
    [set addTarget:self action:@selector(toSet) forControlEvents:UIControlEventTouchUpInside];
    _btn = set;
}

@end

@implementation BRWalletCardTCell

//- (void)setDto:(BRCardModel *)dto {
//    _dto = dto;
//    
//    self.numL.text = [NSString stringWithFormat:@"**** **** **** %@",dto.bankNo];
//    self.expireL.text = [NSString stringWithFormat:@"%@ %@",Localized(@"Card_validThru"),dto.bankExpire];
//    
//    self.isDefault = dto.defaulted;
//    self.nameL.text = dto.bankName;
//    
//    STPCardBrand cardBrand = [STPCard brandFromString:dto.bankName];
//    UIImage *img = [// // // STPImageLibrary (已在新版本中移除) (已在新版本中移除) (已在新版本中移除) brandImageForCardBrand:cardBrand];
//    self.cardImg.image = img;
//}

- (void)setIsDefault:(BOOL)isDefault {
    _isDefault = isDefault;
    self.defaultBGView.hidden = !isDefault;
}

- (void)setDto:(BRCardModel *)dto {
    _dto = dto;
    
    self.nameL.text = dto.bankName;
    self.numL.text = [NSString stringWithFormat:@"**** **** **** %@",dto.bankNo];
    self.expireL.text = [NSString stringWithFormat:@"%@: %@",Localized(@"wallet_validThru"),dto.bankExpire];
    
    self.isDefault = dto.defaulted;
    
    STPCardBrand cardBrand = [STPCard brandFromString:dto.bankName];
    
    // 修复：// // // STPImageLibrary (已在新版本中移除) (已在新版本中移除) (已在新版本中移除) 在新版本 Stripe 中不存在，使用默认图片或自定义实现
    UIImage *img = nil;
    // 可以根据 cardBrand 设置不同的默认图片
    switch (cardBrand) {
        case STPCardBrandVisa:
            img = [UIImage imageNamed:@"visa_card"] ?: [UIImage systemImageNamed:@"creditcard"];
            break;
        case STPCardBrandMastercard:
            img = [UIImage imageNamed:@"mastercard_card"] ?: [UIImage systemImageNamed:@"creditcard"];
            break;
        case STPCardBrandAmex:
            img = [UIImage imageNamed:@"amex_card"] ?: [UIImage systemImageNamed:@"creditcard"];
            break;
        default:
            img = [UIImage systemImageNamed:@"creditcard"];
            break;
    }
    self.cardImg.image = img;
}

#pragma mark - UI --
- (void)setUI {
    [super setUI];
    
   
    self.cardImg.image = UIImageMake(@"wallet_defaultBank");
    // --------------
    UIView *stackBg = [[UIView alloc] init];
    [self.stackView addArrangedSubview:stackBg];
    
    UIStackView *expireStack = [[UIStackView alloc] init];
    expireStack.spacing = 8;
    [stackBg addSubview:expireStack];
    [expireStack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(12);
        make.top.left.bottom.offset(0);
    }];
    
    self.defaultBGView = [[UIView alloc] init];
    
    self.expireL = [BRToolsView br_label:Localized(@"wallet_validThru") textColor:UIColor.whiteColor font:[UIFont br_fontR:9]];
    self.expireL.numberOfLines = 0;
    
    [expireStack addArrangedSubview:self.defaultBGView];
    [expireStack addArrangedSubview:self.expireL];
    
    UIImageView *defImg = [[UIImageView alloc] initWithImage:UIImageMake(@"wallet_cardDefault")];
    [self.defaultBGView addSubview:defImg];
    [defImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(12);
        make.top.left.bottom.offset(0);
    }];
    
    QMUILabel *defL = [BRToolsView br_label:Localized(@"wallet_default") textColor:UIColor.whiteColor font:[UIFont br_fontR:9]];
    [self.defaultBGView addSubview:defL];
    [defL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(defImg.mas_right).offset(4);
        make.right.offset(0);
        make.centerY.offset(0);
    }];
    
    // --------------
    self.numL = [BRToolsView br_label:@"****  ****  **** ****" textColor:UIColor.whiteColor font:[UIFont fontB:23]];
    [self.bg addSubview:self.numL];
    [self.numL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(28);
        make.right.offset(-2);
        make.top.offset(88);
        make.bottom.offset(-56);
    }];
    
    [self.btn setTitle:Localized(@"wallet_remove") forState:UIControlStateNormal];
}

@end


@implementation BRWalletCardAddTCell

#pragma mark - UI --
- (void)setUI {
    [super setUI];
    
    self.cardImg.image = UIImageMake(@"wallet_defaultBank");
    self.nameL.text = Localized(@"wallet_addBankCard");
    [self.cardImg mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(22);
    }];

    self.subL = [BRToolsView br_label:Localized(@"wallet_addBankHint") textColor:UIColor.whiteColor font:[UIFont br_fontR:9]];
    self.subL.numberOfLines = 0;
    [self.stackView addArrangedSubview:self.subL];
    self.subL.hidden = YES;
    
    UIImageView *add = [[UIImageView alloc] initWithImage:UIImageMake(@"wallet_digital")];
  
    [self.bg addSubview:add];
    [add mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(28);
        make.top.offset(97);
        make.bottom.offset(-65);
        make.width.mas_equalTo(180);
        make.height.mas_equalTo(10);
    }];
    
    [self.btn setTitle:Localized(@"wallet_add") forState:UIControlStateNormal];
}

@end


@interface BRWalletCardListTBCell ()<QMUITableViewDelegate,QMUITableViewDataSource>

@end

@implementation BRWalletCardListTBCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BRWalletCardListCellV2 *cell = [tableView dequeueReusableCellWithIdentifier:@"BRWalletCardListCellV2"];
    
    if (cell == nil) {
        cell = [[BRWalletCardListCellV2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BRWalletCardListCellV2"];
    }
    
    cell.line.hidden = self.datas.count - 1 == indexPath.row;
    
    cell.dto = self.datas[indexPath.row];
    
    WS(weakSelf);
    cell.removeBlcok = ^{
        weakSelf.removeBlcok(indexPath.row);
    };
    
    
    return cell;
}

- (void)setDatas:(NSArray *)datas {
    _datas = datas;
    
    CGFloat h = datas.count * 58;
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(h);
    }];
    
    [self.tableView reloadData];
}

#pragma mark - UI --
- (void)setUI {
    
    self.backgroundColor = UIColorClear;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    self.tableView.layer.cornerRadius = 10;
    self.tableView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(0);
        make.left.offset(16);
        make.right.offset(-16);
        make.bottom.top.offset(0);
    }];
}

- (QMUITableView *)tableView {
    
    if (_tableView == nil) {
        
        UITableViewStyle styyle = UITableViewStylePlain;
        _tableView = [[QMUITableView alloc] initWithFrame:CGRectMake(0,kSafeAreaTopHeight, kScreenWidth, kScreenHeight - kSafeAreaTopHeight) style:styyle];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }

        if (@available(iOS 15.0, *)) {
            [UITableView appearance].sectionHeaderTopPadding = 0;
        }
        if (@available(iOS 11.0, *)) {
            self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView.estimatedRowHeight = 58;
        _tableView.rowHeight = 58;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
    }
    
    return _tableView;
}

@end

@implementation BRWalletCardListCellV2

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (void)setDto:(BRCardModel *)dto {
    _dto = dto;
    
    self.reBtn.hidden = NO;
    
    if ([dto.bankName isEqualToString:Localized(@"wallet_type_applepay")]) {
        self.reBtn.hidden = YES;
        self.titleL.text = dto.bankName;
        self.typeImg.image = UIImageMake(dto.bankType);
        
        return;
    }
    
//    self.nameL.text = dto.bankName;
    NSString *bankNo = [NSString stringWithFormat:@"**** **** **** %@",dto.bankNo];
    if (dto.expire == 1) {
        bankNo = [NSString stringWithFormat:@"%@·%@",bankNo,Localized(@"coupon_expired")];
    }
    self.titleL.text = bankNo;
//    self.expireL.text = [NSString stringWithFormat:@"%@: %@",Localized(@"wallet_validThru"),dto.bankExpire];
    
    self.contView.alpha = dto.expire == 1 ? 0.2 : 1;
    
    STPCardBrand cardBrand = [STPCard brandFromString:dto.bankName];
    
    // 修复：// // // STPImageLibrary (已在新版本中移除) (已在新版本中移除) (已在新版本中移除) 在新版本 Stripe 中不存在，使用默认图片或自定义实现
    UIImage *img = nil;
    // 可以根据 cardBrand 设置不同的默认图片
    switch (cardBrand) {
        case STPCardBrandVisa:
            img = [UIImage imageNamed:@"visa_card"] ?: [UIImage systemImageNamed:@"creditcard"];
            break;
        case STPCardBrandMastercard:
            img = [UIImage imageNamed:@"mastercard_card"] ?: [UIImage systemImageNamed:@"creditcard"];
            break;
        case STPCardBrandAmex:
            img = [UIImage imageNamed:@"amex_card"] ?: [UIImage systemImageNamed:@"creditcard"];
            break;
        default:
            img = [UIImage systemImageNamed:@"creditcard"];
            break;
    }
    self.typeImg.image = img;
}

- (void)removeCard {
    if (self.removeBlcok) {
        self.removeBlcok();
    }
}


#pragma mark - UI --
- (void)setUI {
    
    self.contView = [[UIView alloc] init];
    [self.contentView addSubview:self.contView];
    [self.contView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    
    UIView *imgBG = [[UIView alloc] init];
    [self.contView addSubview:imgBG];
    [imgBG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(2);
        make.top.bottom.offset(0);
        make.width.mas_equalTo(74);
    }];
    self.typeImg = [[UIImageView alloc] init];
    
    [imgBG addSubview:self.typeImg];
    [self.typeImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.offset(16);
        make.centerX.offset(0);
//        make.bottom.offset(-14);
        make.centerY.offset(0);
//        make.height.mas_equalTo(30);
//        make.width.mas_equalTo(44);
    }];
    
    self.titleL = [BRToolsView br_label:@"--" textColor:kColorTitle font:[UIFont br_fontS:14]];
    [self.contView addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(76);
        make.right.offset(-26);
    }];
    self.titleL.adjustsFontSizeToFitWidth = YES;
    
    self.line = [[UIView alloc] init];
    self.line.backgroundColor = UIColorMakeWithHex(@"#E4E4E6");
    [self.contentView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.offset(0);
        make.height.mas_equalTo(0.5);
        make.left.offset(76);
    }];
    
    self.reBtn = [[QMUIButton alloc] init];
//    [self.reBtn setTitle:Localized(@"wallet_remove") forState:UIControlStateNormal];
//    self.reBtn.layer.cornerRadius = 13;
//    self.reBtn.layer.borderColor = kColorMain.CGColor;
//    self.reBtn.layer.borderWidth = 0.5;
//    self.reBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 12);
    [self.reBtn setImage:UIImageMake(@"cards_ic_del") forState:UIControlStateNormal];
//    [self.reBtn setTitleColor:kColorMain forState:UIControlStateNormal];
//    self.reBtn.titleLabel.font = [UIFont br_fontR:12];
    [self.contentView addSubview:self.reBtn];
    [self.reBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.offset(0);
        make.width.mas_equalTo(56);
        make.height.mas_equalTo(44);
    }];
    [self.reBtn addTarget:self action:@selector(removeCard) forControlEvents:UIControlEventTouchUpInside];
}



@end
